﻿using BrmMall.Ship.DaDa;
using Ship.DaDa;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrnMall.Ship.DaDa
{
    class Program
    {
        static void Main(string[] args)
        {
            // Echo(DaDaSdk.GetCityCode());

            //Echo(DaDaSdk.QueryFee("", "深圳").Result.Fee);
            //Echo(SDK.QueryFee(DaDaSdk.GetOrderInfo()));
            //Echo(SDK.GetBalance(3));

            //Echo(SDK.AddOrder(DaDaSdk.GetOrderInfo()));



            //Echo(SDK.GetOrder("2018010901"));

            var store = new Core.StoreInfo() { StoreId = 100001, Name = "企动小程序（旗舰店）", Location = "22.543721,114.101514", Address = "玉田大厦", Phone = "0755-83651022" };
            // DaDaHelper.AddShop(store);

            var order = new Core.OrderInfo() { StoreId = 100001, OSN = "2017061418392641007376", OrderAmount = 300, Consignee = "王先生", Address = "玉田大厦409", Mobile = "13811117777" };

            //  Echo(DaDaHelper.QueryFee(order, 114.06819, 22.534854).Fee);

            //Echo(DaDaHelper.GetShop("2").Result.station_name);
        }

        #region 注释
        /*
         * 
        static string GetUrl(string path)
        {
            return string.Concat(Config.api_url_test, path);
        }

        public static string AddOrder()
        {
            return Request(getOrderInfo(), GetUrl(Config.api_queryDeliverFee));
        }

        /// <summary>
        /// 添加订单
        /// </summary>
        /// <param name="model">查询订单费用</param>
        /// <returns></returns>
        public static string QueryFee(Hashtable model)
        {
            return Request(model, GetUrl(Config.api_queryDeliverFee));
        }

        //添加订单
        static Hashtable getOrderInfo()
        {
            Hashtable ht = new Hashtable();
            ht.Add("shop_no", 11047059);
            ht.Add("origin_id", "2018010901");
            ht.Add("city_code", "021");
            ht.Add("cargo_price", 10);
            ht.Add("is_prepay", 0);
            ht.Add("expected_fetch_time", ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds).ToString().Substring(0, 10));
            ht.Add("receiver_name", "测试");
            ht.Add("receiver_address", "上海市崇明岛");
            ht.Add("receiver_lat", 31.2);
            ht.Add("receiver_lng", 121.5);
            ht.Add("callback", "http,//localhost:8081/receive");
            ht.Add("receiver_phone", "18588888888");
            ht.Add("receiver_tel", "18599999999");
            ht.Add("tips", 0);
            ht.Add("info", "测试订单");
            ht.Add("cargo_type", 1);
            ht.Add("cargo_weight", 10.0);
            ht.Add("cargo_num", 100);
            ht.Add("invoice_title", "测试");
            ht.Add("deliver_locker_code", "001");
            ht.Add("pickup_locker_code", "001");
            ht.Add("origin_mark", "abcdefg");
            ht.Add("origin_mark_no", "abcdefg001");
            ht.Add("insurance_fee", 1);
            ht.Add("is_finish_code_needed", 0);
            return ht;
        }

        //重发订单
        public static Hashtable readdOrder()
        {
            Hashtable ht = new Hashtable();
            ht.Add("shop_no", 11047059);
            ht.Add("origin_id", "2018010901");
            ht.Add("city_code", "0755");
            ht.Add("cargo_price", 100);
            ht.Add("is_prepay", 0);
            ht.Add("expected_fetch_time", ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds).ToString().Substring(0, 10));
            ht.Add("receiver_name", "测试");
            ht.Add("receiver_address", "上海市崇明岛");
            ht.Add("receiver_lat", 31.2);
            ht.Add("receiver_lng", 121.5);
            ht.Add("callback", "http,//localhost:8081/receive/");
            ht.Add("receiver_phone", "18588888888");
            ht.Add("receiver_tel", "18599999999");
            ht.Add("tips", 0);
            ht.Add("info", "测试订单");
            ht.Add("cargo_type", 1);
            ht.Add("cargo_weight", 10.0);
            ht.Add("cargo_num", 100);
            ht.Add("expected_finish_time", ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds).ToString().Substring(0, 10));
            ht.Add("invoice_title", "测试");
            ht.Add("deliver_locker_code", "001");
            ht.Add("pickup_locker_code", "001");
            ht.Add("origin_mark", "abcdefg");
            ht.Add("origin_mark_no", "abcdefg001");
            ht.Add("insurance_fee", 1);
            ht.Add("is_finish_code_needed", 0);
            return ht;
        }
        //平台订单编号进行发单
        public static Hashtable deliveryOrder(string deliveryNo)
        {
            Hashtable ht = new Hashtable();
            ht.Add("deliveryNo", deliveryNo);
            return ht;
        }
        //订单增加小费
        public static Hashtable addTipOrder()
        {
            Hashtable ht = new Hashtable();
            ht.Add("order_id", "2018010901");
            ht.Add("tips", "100.0");
            ht.Add("city_code", "0755");
            ht.Add("info", "测试数据");
            return ht;
        }
        //订单回调
        public static Hashtable orderCallback()
        {
            Hashtable ht = new Hashtable();
            ht.Add("client_id", "");
            ht.Add("order_id", "2018010901");
            ht.Add("order_status", 1);
            ht.Add("cancel_reason", "");
            ht.Add("cancel_from", 0);
            ht.Add("update_time", (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds);
            Hashtable tempht = new Hashtable();
            tempht.Add("client_id", "");
            tempht.Add("order_id", "2018010901");
            tempht.Add("update_time", (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds);
            ht.Add("signature", Function.GetSignForCallback(tempht));
            ht.Add("dm_id", "18599999999");
            ht.Add("dm_name", "张三");
            ht.Add("dm_mobile", "18599999999");
            return ht;
        }
        //查询订单的骑手记录
        public static Hashtable orderstatusquery()
        {
            Hashtable ht = new Hashtable();
            ht.Add("order_id", "2018010901");
            return ht;
        }
        //取消订单
        public static Hashtable cancelOrder()
        {
            Hashtable ht = new Hashtable();
            ht.Add("order_id", "2018010901");
            ht.Add("cancel_reason_id", 1);
            ht.Add("cancel_reason", "");
            return ht;
        }
        //追加订单
        public static Hashtable appointOrder()
        {
            Hashtable ht = new Hashtable();
            ht.Add("order_id", "2018010901");
            ht.Add("transporter_id", 1);
            ht.Add("shop_no", 11047059);
            return ht;
        }
        //取消追加的订单
        public static Hashtable appointOrderCancel()
        {
            Hashtable ht = new Hashtable();
            ht.Add("order_id", "2018010901");
            return ht;
        }
        //追加配送员
        public Hashtable transporter()
        {
            Hashtable ht = new Hashtable();
            ht.Add("shop_no", 11047059);
            return ht;
        }
        //注册商铺信息(注：调用该接口签名中source_id参数需传空字符串)
        public static Hashtable merchantadd()
        {
            Hashtable ht = new Hashtable();
            ht.Add("mobile", "");
            ht.Add("city_name", "");
            ht.Add("enterprise_name", "");
            ht.Add("enterprise_address", "");
            ht.Add("contact_name", "");
            ht.Add("contact_phone", "");
            ht.Add("email", "");
            return ht;
        }
        //新增门店信息
        public static Hashtable shopadd()
        {
            Hashtable ht = new Hashtable();
            ht.Add("station_name", "");
            ht.Add("business", "");
            ht.Add("city_name", "上海");
            ht.Add("area_name", "浦东新区");
            ht.Add("station_address", "");
            ht.Add("lng", "");
            ht.Add("lat", "");
            ht.Add("contact_name", "");
            ht.Add("phone", "");
            ht.Add("origin_shop_id", "");
            ht.Add("id_card", "");
            ht.Add("username", "");
            ht.Add("password", "");
            return ht;
        }
        //更新门店信息
        public static Hashtable shopupdate()
        {
            Hashtable ht = new Hashtable();
            ht.Add("origin_shop_id", "");
            ht.Add("new_shop_id", "");
            ht.Add("station_name", "");
            ht.Add("business", 1);
            ht.Add("city_name", "上海");
            ht.Add("area_name", "浦东新区");
            ht.Add("station_address", "");
            ht.Add("lng", 30.1);
            ht.Add("lat", 40.5);
            ht.Add("contact_name", "");
            ht.Add("phone", "");
            ht.Add("status", 1);
            return ht;
        }
        //门店信息详情
        public static Hashtable shopdetail()
        {
            Hashtable ht = new Hashtable();
            ht.Add("origin_shop_id", "");
            return ht;
        }
        //商家投诉达达
        public static Hashtable shopcomplaint()
        {
            Hashtable ht = new Hashtable();
            ht.Add("order_id", "");
            ht.Add("reason_id", 1);
            return ht;
        }
        //充值链接
        public static Hashtable shoprecharge()
        {
            Hashtable ht = new Hashtable();
            ht.Add("amount", 100.0);
            ht.Add("category", "PC");
            ht.Add("notify_url", 1);
            return ht;
        }
        //查询账户余额
        public static Hashtable balancequery()
        {
            Hashtable ht = new Hashtable();
            ht.Add("category", 3);
            return ht;
        }


        /// <summary>
        /// 达达发送数据主体
        /// </summary>
        /// <param name="htbody">body数据体</param>
        /// <returns></returns>
        public static Hashtable MainMap(Hashtable htbody)
        {
            Hashtable ht = new Hashtable();
            ht.Add("body", Function.ToJson(htbody));
            ht.Add("format", "json");
            ht.Add("timestamp", ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds).ToString().Substring(0, 10));
            ht.Add("app_key", Config.app_key);
            ht.Add("v", "1.0");
            ht.Add("source_id", 73753);
            return ht;
        }

        /// <summary>
        /// 输出结果
        /// </summary>
        /// <param name="htorder">发送数据</param>
        /// <param name="url">发送地址</param>
        static string Request(Hashtable htorder, string url)
        {
            Hashtable ht = MainMap(htorder);
            ht.Add("signature", Function.GetSign(ht));
            string html = HttpHelper.GetHtml(url, Function.ToJson(ht));
            WriteText(html);
            return html;
        }

        /// <summary>
        /// 返回有数据的结果
        /// </summary>
        /// <param name="htorder"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string print2(Hashtable htorder, string url)
        {
            Hashtable ht = MainMap(htorder);
            ht.Add("signature", Function.GetSign(ht));
            return HttpHelper.GetHtml(url, Function.ToJson(ht));
        }

        */
        #endregion

        static void Echo(object msg)
        {
            Console.WriteLine(msg);
        }

        public static void WriteText(string text)
        {
            Console.WriteLine(text);
        }
    }
}
